package com.qiyu;

import cn.hutool.db.Entity;
import cn.hutool.json.JSONUtil;
import com.qiyu.entity.Student;
import com.qiyu.service.StudentServiceUtil;

import java.util.List;

/**
 * @Author： gebilaozhongyi
 * @Company：
 * @CreateTime： 2024-06-28 20:39
 * @Description：
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        //给你一个数据库表结构，让你对该表进行增删改查操作
        //然后查询出某一门课程的平均成绩或者不及格的学生数
        // 初始化数据
//
        StudentServiceUtil.initStudents();
//        // 添加
//        addStudent();
//        // 删除
//        deleteStudent();
//        // 修改
//        updateStudent();
//        // 查询
        selectStudent("s1");
//        // 查询平均成绩
//        queryAvgScore();
//        // 查询不及格的学生数
//        queryLowScoreCount();

    }

    private static void queryLowScoreCount() {
        System.out.println("不及格的学生数：" + StudentServiceUtil.queryLowScoreCount());
    }

    private static void queryAvgScore() {
        Entity entitie = StudentServiceUtil.queryAvgScore();
        Integer math = entitie.getInt("math");
        Integer english = entitie.getInt("english");
        Integer china = entitie.getInt("china");
        System.out.println("数学平均成绩：" + math);
        System.out.println("英语平均成绩：" + english);
        System.out.println("语文平均成绩：" + china);
        System.out.println("三科平均成绩：" + (math + english + china) / 3);
    }

    private static void selectStudent(String s1) {
        List<Entity> students = StudentServiceUtil.selectStudent(s1);
        for (Entity student : students) {
            System.out.println(JSONUtil.toJsonPrettyStr(student));
        }
    }

    private static void updateStudent() {
    }

    private static void deleteStudent() {
    }

    private static void addStudent() {
        Student student = new Student();
        StudentServiceUtil.addStudent(student);
    }

}